package com.example.xm.controller;

import com.example.xm.entity.Cartentity;
import com.example.xm.entity.vo.CartListVo;
import com.example.xm.service.CartService;
import com.example.xm.web.Result;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/cart")
public class CartController {
    @Autowired
    CartService cartService;
    @PostMapping("/add")
    public Result add(@RequestBody Cartentity cartentity){
        cartService.add(cartentity);
        return Result.success();
    }
    @GetMapping("/list")
    public Result list(Cartentity cartentity){
      List<CartListVo> cartListVos= cartService.list(cartentity);
      return Result.success(cartListVos);
    }
    @PostMapping("/update")
    public Result update(@RequestBody Cartentity cartentity){
        cartService.update(cartentity);
        return Result.success();
    }
    @GetMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        cartService.deleteById(id);
        return Result.success();
    }
}
